<!--  -->
<template>
  <div class="main">
    <el-container>
      <el-header>翠花，上茶....</el-header>
      <el-container>
        <el-aside :width="isCollapse ? '64px' : '200px'">
          <div class="toggle-button" @click="toggleCollapse">
            <span v-if="isCollapse">展开</span>
            <span v-else>收起</span>
          </div>
          <el-menu
            default-active="/userlist"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b"
            :unique-opened="true"
            :router="true"
            :collapse="isCollapse"
            :collapse-transition="false"
          >
            <el-submenu
              v-for="items in list"
              :key="items.id"
              :index="items.path"
            >
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>{{ items.title }}</span>
              </template>
              <el-menu-item
                v-for="item in items.child"
                :key="item.id"
                :index="item.path"
              >
                <template slot="title">
                  <i class="el-icon-location"></i>
                  <span>{{ item.title }}</span>
                </template>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';

export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    //这里存放数据
    return {
      isCollapse: false,
      list: [
        {
          id: 1,
          title: "用户管理",
          path: "userlist",
          child: [
            {
              id: 1001,
              title: "用户列表",
              path: "userlist",
            },
            {
              id: 1002,
              title: "添加用户",
              path: "adduser",
            },
          ],
        },
        {
          id: 2,
          title: "商品管理",
          path: "goodslist",
          child: [
            {
              id: 2001,
              title: "分类列表",
              path: "catelist",
            },
            {
              id: 2002,
              title: "商品列表",
              path: "goodslist",
            },
          ],
        },
      ],
    };
  },
  methods: {
    toggleCollapse() {
      this.isCollapse = !this.isCollapse;
    },
  },
};
</script>
<style lang="less">
.main {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  .el-container {
    height: 100%;
    .el-header {
      background: rgb(45, 1, 117);
      display: flex;
      justify-content: space-between;
      align-items: center;
      color: #fff;
      font-size: 20px;
    }
    .el-aside {
      height: 100%;
      background: #545c64;
      .toggle-button {
        height: 30px;
        background: pink;
        span{
          display: block;
          text-align: center;
          line-height: 30px;
          color: #f55;
        }
      }
    }
    .el-menu {
      border-right: 0;
    }
  }
}
</style>